//
// Created by 11510 on 2024/6/23.
//

#ifndef TEXTQUERY_QUERYRESULT_H
#define TEXTQUERY_QUERYRESULT_H

#include <iostream>
#include <memory>
#include <vector>
#include <set>
#include <map>

using std::string;
using std::vector;
using std::map;
using std::set;
using std::shared_ptr;

class QueryResult {
    using line_no = vector<string>::size_type;
    friend std::ostream &operator<<(std::ostream &os, const QueryResult &queryResult);

public:
    QueryResult(string s,
                shared_ptr<set<line_no>> p,
                shared_ptr<vector<string>> f) :
            sought(s), lines(p), file(f) {}

    set<size_t>::iterator begin() {
        return lines->begin();
    }

    set<size_t>::iterator end() {
        return lines->end();
    }

    shared_ptr<vector<string>> get_file() {
        // 返回智能指针的拷贝
        return shared_ptr<vector<string>>(file);
    }

private:
    string sought; // 查询的单词
    shared_ptr<set<line_no>> lines; // 单词所在的行号
    shared_ptr<vector<string>> file; // 输入文件的每一行
};

std::ostream &operator<<(std::ostream &os, const QueryResult &queryResult);

#endif //TEXTQUERY_QUERYRESULT_H
